<template>
  <div>
    <div class="top">
      <Search @search="search">
        <template>区域搜索</template>
      </Search>
    </div>
    <div class="bottom">
      <div class="bottom-top">
        <el-button type="warning" icon="el-icon-circle-plus-outline" @click="ishow">新建</el-button>
      </div>
      <div class="bottom-bot">
        <div class="block">
          <!-- 列表区域 -->
          <el-table :data="regionList" style="width: 100%">
            <el-table-column type="index" label="序号" width="80" ></el-table-column>
            <!-- <el-table-column prop="index" label="序号" width="80" ></el-table-column> -->
            <el-table-column prop="name" label="区域名称" width="" ></el-table-column>
            <el-table-column prop="nodeCount" label="点位数" width=""> </el-table-column>
            <el-table-column prop="remark" label="备注说明" width=""> </el-table-column>
            <el-table-column prop="operate" label="操作" width="180" >
              <template #default="{ row }">
               <el-link type="primary" style="margin-right: 5px;" :underline="false" @click="view(row)">查看详情</el-link>
               <el-link type="primary" style="margin-right: 5px;" :underline="false" @click="revise(row.id,row.name,row.remark)">修改</el-link>
               <el-link type="danger" style="margin-right: 5px;" :underline="false" @click="delarea(row.id)">删除</el-link>
              </template>
            </el-table-column>
          </el-table>
          <FootBtn :totalCount="totalCount"  @goup="goup" :region="this.region"/>
        </div>
      </div>
    </div>
    <!-- 新建弹窗 -->
    <Eject :dialogFormVisible.sync="dialogFormVisible" @revisearea="revisearea" @Ent="addarea" @ishow="ishowT" :specific="specific" :specifi="specifi"/>
    <!-- 查看详情弹窗· -->
    <el-dialog
      title="区域详情"
      :visible.sync="dialogTwo"
      width="30%"
      :before-close="handleCloseTwo">
      <span>
        <template>
          <!-- <el-form ref="formTwo" :model="form" label-width="80px">
            <el-form-item label="区域名称">
              <el-input v-model="formTwo.name"></el-input>
            </el-form-item>
          </el-form> -->
          <div>
            <el-row>
              <el-col :span="6"><div class="grid-content bg-purple">区域名称：</div></el-col>
              <el-col :span="18"><div class="grid-content bg-purple-light">{{row.name}}</div></el-col>
            </el-row>
          </div>
          <div>
             <el-row>
             
              <el-col :span="6"><div class="grid-content bg-purple">包含点位：</div></el-col>
              <el-col :span="18">
                <div class="grid-content bg-purple-light">
                  <el-table
                    :data="FormTwoData"
                    style="width: 100%">
                    <el-table-column
                      type="index"
                      label="序号"
                      width="140">
                    </el-table-column>
                    <el-table-column
                      prop="name"
                      label="点位名称"
                      width="180">
                    </el-table-column>
                    <el-table-column
                      prop="vmCount"
                      label="设备数量">
                    </el-table-column>
                  </el-table>
                  </div>
                </el-col>
            </el-row>
          </div>
        
        </template>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogTwo = false">取 消</el-button>
        <el-button type="primary" @click="dialogTwo = false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import '@/styles/second/region.scss'
import Search from '@/components/search.vue'
import FootBtn from '@/components/footbtn.vue'
import Eject from '@/components/eject.vue'
import { regionalManagement, addArea, delArea, reviseArea, omn } from '@/api/homePage'
export default {
  components: {
    Search,
    FootBtn,
    Eject
  },
  async created() {
    this.getone()
  },
  data() {
    return {
      // 请求参数
      region: {
        pageIndex: 1,
        pageSize: 10,
        name:'',
        regionId:''
      },
      regionList: [], //每次请求的列表
      totalCount: '', //数据总条数
      dialogFormVisible:false,
      specific:{
        id:'',
        regionName:'',
        remark:''
      },
      specifi:0,
      dialogTwo: false,
      formTwo:{
        name:''
      },
      FormTwoData:{

      },
      row:{}
    }
  },
  methods: {
    goup(val){
      this.region.pageIndex = this.region.pageIndex+val
      this.getone()
    },
    // 搜索
    async search(val){
      if ( this.region.name === '') {
        this.getone()
      }
     this.region.name = val
     this.getone()
    },
    ishow(){
      this.specifi=0
      this.dialogFormVisible = !this.dialogFormVisible
    },
    ishowT(){
      this.dialogFormVisible = !this.dialogFormVisible
    },
    // 修改详情
    async revise(id,name,remark){
      this.specific.id=id,
      this.specific.regionName=name,
      this.specific.remark=remark,
      this.specifi=1
      this.ishowT()
    },
    async revisearea (data) {
       await reviseArea(data)
       this.ishowT()
       this.getone()
    },
    // 增加区域
    async addarea(data) {
      await addArea(data)
      this.ishowT()
      this.getone()
    },
    // 删除区域
    async delarea(id) {
      await delArea(id)
      this.getone()
    },
    // 查看详情
    async view (row) {
      this.region.regionId = row.id
      this.row = row
      const res = await omn(this.region)
      console.log(res);
      this.FormTwoData = res.data.currentPageRecords
      this.dialogTwo = true
    },
    // 查看详情弹窗
    handleCloseTwo(done) {
        this.$confirm('确认关闭？')
          .then(() => {
            done();
          })
          .catch(()=> {});
      },
    // 重复调用接口
    async getone() {
      const { data } = await regionalManagement(this.region)
      this.totalCount = data.totalCount
      this.regionList = data.currentPageRecords
    },
  },
}
</script>

<style></style>
